package star.oath.panel;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class CosmicDialog extends JDialog {

    // 定义主题颜色（从 CSS 提取）
    private static final Color BG_DARK = new Color(28, 10, 45);         // 近似 #1e0030 ~ #2c0a45
    private static final Color GOLD_BORDER = new Color(184, 134, 11);   // #b8860b
    private static final Color GOLD_HOVER = new Color(218, 165, 32);    // #daa520
    private static final Color TEXT_GOLD = new Color(240, 230, 140);    // #f0e68c
    private static final Color BUTTON_BG = new Color(40, 20, 60);       // rgba(40,20,60,0.7)

    public CosmicDialog(Frame owner) {
        super(owner, "Cosmic Dialog", true);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setLayout(new BorderLayout());
        setBackground(BG_DARK);

        // 内容面板
        JPanel contentPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 20, 20)) {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.setColor(BG_DARK);
                g.fillRect(0, 0, getWidth(), getHeight());
            }
        };
        contentPanel.setOpaque(true);
        contentPanel.setBackground(BG_DARK);
        contentPanel.setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(GOLD_BORDER, 2),
                BorderFactory.createEmptyBorder(25, 30, 25, 30)
        ));

        // 创建两个按钮
        JButton btn1 = createCosmicButton("Accept");
        JButton btn2 = createCosmicButton("Decline");

        contentPanel.add(btn1);
        contentPanel.add(btn2);

        add(contentPanel, BorderLayout.CENTER);

        // 窗口整体边框（模拟 container 的 border + shadow）
        getRootPane().setBorder(BorderFactory.createCompoundBorder(
                BorderFactory.createLineBorder(new Color(184, 134, 11, 120), 1),
                BorderFactory.createEmptyBorder()
        ));

        pack();
        setLocationRelativeTo(owner);
    }

    private JButton createCosmicButton(String text) {
        JButton btn = new JButton(text);
        btn.setFocusPainted(false);
        btn.setFont(new Font("Segoe UI", Font.BOLD, 14));
        btn.setForeground(Color.WHITE);
        btn.setBackground(GOLD_BORDER); // #b8860b
        btn.setBorder(BorderFactory.createLineBorder(GOLD_BORDER, 2));

        // 悬停效果
        btn.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                btn.setBackground(GOLD_HOVER); // #daa520
            }

            @Override
            public void mouseExited(MouseEvent e) {
                btn.setBackground(GOLD_BORDER);
            }
        });

        return btn;
    }

    // 测试入口
    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(500, 350);
            frame.getContentPane().setBackground(new Color(20, 10, 30)); // body 背景色近似
            frame.setVisible(true);

            new CosmicDialog(frame).setVisible(true);
        });
    }
}